package com.qianyu.project.service.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.Perform;
import com.qianyu.project.mapper.provider.smj.smjPerformDao;
import com.qianyu.project.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Service
public class smjPerformServiceImpl implements smjPerformService {
    @Autowired
    private smjPerformDao pd;

    @Override//添加完工结算
    public String Addperform(String apply_date, String p_id, String ctr_id, String company_id, String perform_name, String contract_amount, String penalty, String withhold, String agree_amount, String agree_upper, String handler_id, String settle_comment, String attach_ids) {
        String update_date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String[] ids = update_date.split(" ");
        String ids1 =ids[0];
        String ids2 =ids[1];
        String[] ids3 = ids1.split("-");
        String[] ids4 = ids2.split(":");
        String id ="";
        for (int i = 0; i <ids3.length ; i++) {
            id += ids3[i];
        }
        for (int i = 0; i <ids4.length ; i++) {
            id += ids4[i];
        }
        pd.Addperform( id,apply_date, p_id, ctr_id, company_id, perform_name, contract_amount, penalty, withhold,  agree_amount, agree_upper, handler_id, settle_comment, attach_ids);
        return id;
    }

    @Override
    public void Addworklist(String perform_id, String work_content, String work_count, String unit, String unit_price, String snumber, String hnumber, String comment) {
         String sumnumber = Integer.valueOf(snumber)*Integer.valueOf(hnumber)+"";
         pd.Addworklist( perform_id, work_content, work_count, unit, unit_price, snumber, hnumber, sumnumber, comment);
    }

    @FlowBegin("perform")//发起审批
    @Override
    public Integer FlowPerform(@FlowEntry("id") Perform perform) {
        pd.UpdateApproveStatus(1, perform.getId());
        return 1;
    }

    @Override//查询完工结算列表
    public IPage<Map<String, Object>> listPerform(Map<String, String> params) {
        IPage<Map<String, Object>> page= PageUtil.createPage(params);
        return pd.listPerform(page,params);
    }

    @Override//查询工程量清单
    public List<Map<String, Object>> getWorkList(String perform_id) {
        return pd.getWorkList(perform_id);
    }

    @Override
    public List<Map<String, Object>> getfromaudit(String perform_id) {
        String fid = pd.getFid(perform_id);
        return pd.getfromaudit(fid);
    }
}
